package com.cxyzy.demo.ui.activity

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import com.cxyzy.demo.R
import com.cxyzy.demo.ext.obtainViewModel
import com.cxyzy.demo.ui.adapter.UserAdapter
import com.cxyzy.demo.viewmodels.UserViewModel
import kotlinx.android.synthetic.main.activity_user.*

class UserActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_user)
        val viewModel = obtainViewModel(UserViewModel::class.java)
        val adapter = UserAdapter()
        userRv.adapter = adapter
        viewModel.userList.observe(this, Observer { adapter.submitList(it) })

        //设置下拉刷新转圈的颜色
//        swipeRefreshLayout.setColorSchemeColors(Color.RED,Color.BLUE,Color.GREEN)
        swipeRefreshLayout.setOnRefreshListener {
            viewModel.deleteAll()
            viewModel.initData()
            swipeRefreshLayout.isRefreshing = false
        }
    }
}
